package com.nanhai.buddhist.college.module.collegebase.controller.admin.teacherremuneration;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import static com.nanhai.buddhist.college.framework.common.pojo.CommonResult.success;

import com.nanhai.buddhist.college.framework.excel.core.util.ExcelUtils;

import com.nanhai.buddhist.college.framework.operatelog.core.annotations.OperateLog;
import static com.nanhai.buddhist.college.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.nanhai.buddhist.college.module.collegebase.controller.admin.teacherremuneration.vo.*;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.teacherremuneration.TeacherRemunerationDO;
import com.nanhai.buddhist.college.module.collegebase.convert.teacherremuneration.TeacherRemunerationConvert;
import com.nanhai.buddhist.college.module.collegebase.service.teacherremuneration.TeacherRemunerationService;

@Api(tags = "管理后台 - 教师薪酬")
@RestController
@RequestMapping("/collegebase/teacher-remuneration")
@Validated
public class TeacherRemunerationController {

    @Resource
    private TeacherRemunerationService teacherRemunerationService;

    @PostMapping("/create")
    @ApiOperation("创建教师薪酬")
    @PreAuthorize("@ss.hasPermission('collegebase:teacher-remuneration:create')")
    public CommonResult<String> createTeacherRemuneration(@Valid @RequestBody TeacherRemunerationCreateReqVO createReqVO) {
        return success(teacherRemunerationService.createTeacherRemuneration(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新教师薪酬")
    @PreAuthorize("@ss.hasPermission('collegebase:teacher-remuneration:update')")
    public CommonResult<Boolean> updateTeacherRemuneration(@Valid @RequestBody TeacherRemunerationUpdateReqVO updateReqVO) {
        teacherRemunerationService.updateTeacherRemuneration(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除教师薪酬")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('collegebase:teacher-remuneration:delete')")
    public CommonResult<Boolean> deleteTeacherRemuneration(@RequestParam("id") String id) {
        teacherRemunerationService.deleteTeacherRemuneration(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得教师薪酬")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('collegebase:teacher-remuneration:query')")
    public CommonResult<TeacherRemunerationRespVO> getTeacherRemuneration(@RequestParam("id") String id) {
        TeacherRemunerationDO teacherRemuneration = teacherRemunerationService.getTeacherRemuneration(id);
        return success(TeacherRemunerationConvert.INSTANCE.convert(teacherRemuneration));
    }

    @GetMapping("/list")
    @ApiOperation("获得教师薪酬列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('collegebase:teacher-remuneration:query')")
    public CommonResult<List<TeacherRemunerationRespVO>> getTeacherRemunerationList(@RequestParam("ids") Collection<String> ids) {
        List<TeacherRemunerationDO> list = teacherRemunerationService.getTeacherRemunerationList(ids);
        return success(TeacherRemunerationConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得教师薪酬分页")
    @PreAuthorize("@ss.hasPermission('collegebase:teacher-remuneration:query')")
    public CommonResult<PageResult<TeacherRemunerationRespVO>> getTeacherRemunerationPage(@Valid TeacherRemunerationPageReqVO pageVO) {
        PageResult<TeacherRemunerationDO> pageResult = teacherRemunerationService.getTeacherRemunerationPage(pageVO);
        return success(TeacherRemunerationConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出教师薪酬 Excel")
    @PreAuthorize("@ss.hasPermission('collegebase:teacher-remuneration:export')")
    @OperateLog(type = EXPORT)
    public void exportTeacherRemunerationExcel(@Valid TeacherRemunerationExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<TeacherRemunerationDO> list = teacherRemunerationService.getTeacherRemunerationList(exportReqVO);
        // 导出 Excel
        List<TeacherRemunerationExcelVO> datas = TeacherRemunerationConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "教师薪酬.xls", "数据", TeacherRemunerationExcelVO.class, datas);
    }

}
